/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#include "mod_log.h"

namespace sleepyface
{
    namespace arch
    {
        namespace modules
        {
			void Log::log(int c, string m)
			{
				z_msg msg = z_msg_init(c, (char *)m.c_str());
				z_msg_dump(&_log, &msg);
				z_msg_eval(&msg);
				z_msg_release(msg);
			}

            Log::Log() : ArchModule()
            {
                setName("log");
            }

            int Log::signal(ModuleSignal s, Architecture &a)
            {
                if (s.getCode() == signalInitialize)
                {
                    _log = z_log_init_with_file(stdout);
                    return 0;
                }
                else if (s.getCode() == signalUninitialize)
                {
                    z_log_release(_log);
                    return 0;
                }
                else if (s.getCode() == signalLog)
                {
					log(s.getData(0).getInt(), s.getData(1).getString());
                    return 0;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
}
